package cn.wbu.zyh.mapper;

import cn.wbu.zyh.annotation.AutoFill;
import cn.wbu.zyh.entity.ArticleTag;
import cn.wbu.zyh.enumeration.OperationType;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ArticleTagMapper {
    @Select("SELECT t.name " +
            "FROM article_tag at " +
            "LEFT JOIN tag t ON at.tag_id = t.id " +
            "WHERE at.article_id = #{articleId}")
    List<ArticleTag> getByArticleId(Long articleId);

    void insertBatch(List<ArticleTag> articleTags);

    @Insert("insert into article_tag(article_id,tag_id) VALUES (#{articleId},#{tagId})")
    void insert(ArticleTag newArticleTag);

//    @Delete("DELETE article_tag, tag " +
//            "FROM article_tag " +
//            "JOIN tag ON article_tag.tag_id = tag.id " +
//            "WHERE article_tag.article_id = #{articleId}")
//
//    void deleteByArticleId(Long articleId);
    @Delete("DELETE FROM article_tag WHERE article_id = #{articleId}")
    void deleteByArticleId(Long articleId);

}
